<template>
  <page-container :scrollY="false">
    <search-form
      v-model="searchForm"
      :searchColumns="searchColumns"
      :searchOptions="{ menuSpan: 5 }"
      @on-search="handleSearch">
    </search-form>
    <el-row style="height: 100%; width: 100%">
      <el-col
        style="height: 100%"
        :span="device === 'mobile' ? 24 : 12">
        <el-row style="height: 100%; width: 100%">
          <el-col style="height: 50%"> <RegionPiechart></RegionPiechart></el-col>
          <el-col style="height: 50%"> <SalePiechart></SalePiechart></el-col>
        </el-row>
      </el-col>
      <el-col
        style="height: 99%"
        :span="device === 'mobile' ? 24 : 12">
        <avue-table
          :dataList="dataList"
          :loading="loading"
          :page="page"
          :tableColumns="tableColumns"
          :tableOptions="{ menu: false }"
          @onPageChange="onPageChange">
          <template v-slot:menu="{ row }">
            <el-button
              type="primary"
              icon="el-icon-edit"
              circle
              @click="handleView(row)">
            </el-button>
          </template>
        </avue-table>
      </el-col>
    </el-row>
  </page-container>
</template>

<script>
import tableMixins from '@/mixins/table'
import { deepClone } from '@/utils'
import { mapGetters } from 'vuex'
import { searchColumns, tableColumns } from './config/table-config'
import { queryMovieBoardList } from '@/api/userData'
import SalePiechart from './components/sale-piechart.vue'
import RegionPiechart from './components/region-piechart.vue'

export default {
  components: { SalePiechart, RegionPiechart },
  mixins: [tableMixins],
  data() {
    return {
      actionType: 'add',
      dataList: [],
      childList: [],
      searchForm: {
        dateRange: [this.$startStamp(new Date()), this.$endStamp(new Date())],
      },
      editForm: {},
    }
  },
  computed: {
    ...mapGetters(['commonData', 'device']),
    userList() {
      return this.commonData?.userList ?? []
    },
    searchColumns,
    tableColumns,
  },
  methods: {
    fetchMethod: queryMovieBoardList,

    // 查询参数格式化
    formatSearch() {
      const searchParams = deepClone(this.searchForm)
      const [start, end] = this.searchForm.dateRange
      searchParams.start = start && this.$dayjs(this.$startStamp(start)).unix()
      searchParams.end = end && this.$dayjs(this.$endStamp(end)).unix()
      delete searchParams.dateRange
      return searchParams
    },

    // 表格操作
    handleView(row) {
      console.log(row)
      this.$router.push({
        path: '/dashboard/simple_film',
        query: { name: row?.film_name, id: row?.film_id },
      })
    },
  },
  mounted() {
    this.handleSearch()
  },
}
</script>

<style lang="scss" scoped></style>
